package com.example.wallpaperapp.ui.fragment;

import android.content.Context;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.example.wallpaperapp.R;
import com.example.wallpaperapp.adapter.ImageNetAdapter;
import com.example.wallpaperapp.adapter.MomentHotAdapter;
import com.example.wallpaperapp.base.BaseFragment;
import com.example.wallpaperapp.bean.DataBean;
import com.example.wallpaperapp.bean.FindPreviewBean;
import com.example.wallpaperapp.bean.Moment;
import com.example.wallpaperapp.ui.activity.FindPreviewActivity;
import com.example.wallpaperapp.utils.IntentUtil;
import com.example.wallpaperapp.utils.RecyclerViewSpacesItemDecoration;
import com.example.wallpaperapp.utils.ToastUtil;
import com.youth.banner.Banner;
import com.youth.banner.indicator.CircleIndicator;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cn.bingoogolapple.baseadapter.BGAOnRVItemClickListener;
import cn.bingoogolapple.baseadapter.BGAOnRVItemLongClickListener;
import cn.bingoogolapple.photopicker.imageloader.BGARVOnScrollListener;
import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;


public class FindHotFragment extends BaseFragment implements BGAOnRVItemClickListener, BGAOnRVItemLongClickListener, BGANinePhotoLayout.Delegate {
    private RecyclerView mMomentRv;
    private MomentHotAdapter mMomentAdapter;
    private BGANinePhotoLayout mCurrentClickNpl;
    private Banner banner;
    List<Moment> moments;
    @Override
    protected void initView(View view) {
        banner = view.findViewById(R.id.find_hot_banner);
        banner.setAdapter(new ImageNetAdapter(DataBean.getTestData3()));
        //设置指示器
        banner.setIndicator(new CircleIndicator(getActivity()));
        //添加画廊效果(可以和其他PageTransformer组合使用，比如AlphaPageTransformer，注意但和其他带有缩放的PageTransformer会显示冲突)
        banner.setBannerGalleryEffect(18,10);

        mMomentRv = view.findViewById(R.id.rv_hot_list_moments);
        mMomentAdapter = new MomentHotAdapter(mMomentRv,this);
        mMomentRv.addOnScrollListener(new BGARVOnScrollListener(getActivity()));
        mMomentRv.setLayoutManager(new LinearLayoutManager(getActivity()));
        mMomentAdapter.setOnRVItemClickListener(this);
        mMomentAdapter.setOnRVItemLongClickListener(this);
        mMomentRv.addItemDecoration(new RecyclerViewSpacesItemDecoration(RecyclerViewSpacesItemDecoration.TOP_DECORATION,20));
        mMomentRv.setAdapter(mMomentAdapter);
        addNetImageTestData();
    }
    /**
     * 添加网络图片测试数据
     */
    private void addNetImageTestData() {
        moments = new ArrayList<>();
        moments.add(new Moment("1张网络图片", new ArrayList<>(Arrays.asList("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603697069543&di=52ea9deab5e252f7003b54c691d159e7&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F64%2F52%2F01300000407527124482522224765.jpg")),"1"));
        moments.add(new Moment("小明","https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603697069543&di=52ea9deab5e252f7003b54c691d159e7&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F64%2F52%2F01300000407527124482522224765.jpg","1张网络图片", new ArrayList<>(Arrays.asList("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603697069543&di=52ea9deab5e252f7003b54c691d159e7&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F64%2F52%2F01300000407527124482522224765.jpg")),"1","2"));
        moments.add(new Moment("2张网络图片", new ArrayList<>(Arrays.asList("http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered2.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered3.png"))));
        moments.add(new Moment("5张网络图片", new ArrayList<>(Arrays.asList("http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered11.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered12.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered13.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered14.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered15.png"))));
        ArrayList<String> photos = new ArrayList<>();
        for (int i = 1; i < 10; i++) {
            photos.add("http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered" + i + ".png");
        }
        moments.add(new Moment("18张网络图片", photos));
        mMomentAdapter.setData(moments);
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_find_hot;
    }
    @Override
    protected void initData(Context context) {

    }

    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {
        ToastUtil.makeText(getActivity(),"点击了"+position);
        Intent intent = new Intent(getActivity(), FindPreviewActivity.class);
        Bundle bundle = new Bundle();
        Moment moment = moments.get(position);
        List<FindPreviewBean> findPreviewBeanlist = new ArrayList<>();
        findPreviewBeanlist.add(new FindPreviewBean(moment.userName,moment.UserPhoto,moment.content,moment.photos));
        bundle.putSerializable("llgData", (Serializable) findPreviewBeanlist);
        intent.putExtras(bundle);
        //IntentUtil.startActivity(FindPreviewActivity.class,bundle,getActivity());
        startActivity(intent);
    }

    @Override
    public boolean onRVItemLongClick(ViewGroup parent, View itemView, int position) {
        return false;
    }

    @Override
    public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
        mCurrentClickNpl = ninePhotoLayout;

    }

    @Override
    public void onClickExpand(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
        ninePhotoLayout.setIsExpand(true);
        ninePhotoLayout.flushItems();
    }

    @Override
    public void onClick(View v) {

    }
}